package com.zy.scwuser.controller;

import com.zy.scwcommon.bean.AppResponse;
import com.zy.scwcommon.entity.TMember;
import com.zy.scwcommon.entity.TMemberAddress;
import com.zy.scwcommon.vo.user.UserAddressVo;
import com.zy.scwuser.service.TMemberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.rmi.CORBA.Util;
import java.util.ArrayList;
import java.util.List;

/**
* @program: zyzc_springcloud
*
* @description: 发起人表相关的接口信息
*
* @author: ZYY
*
* @create: 2024-07-18 10:02
**/
@Api(tags = "发起人表---模块")
@RequestMapping("/user/info")
@RestController
@Slf4j
public class TmemberController {
    @Autowired
    TMemberService tMemberService;
    @Autowired
    StringRedisTemplate redisTemplate;
    @GetMapping("/selectById")
   public AppResponse<TMember> selectById(@RequestParam("id") Integer id){
       TMember tMember = tMemberService.selectById(id);
      return AppResponse.ok(tMember);
   }

    @ApiOperation(value="获取用户收货地址")
    @GetMapping("/address1")
    public AppResponse<List<UserAddressVo>> address(@RequestParam("accessToken") String accessToken){
        // Integer memberId = Integer.parseInt (accessToken);
        String mem = redisTemplate.opsForValue ().get (accessToken);
        if(StringUtils.isEmpty(mem)){
           AppResponse.fail (null);
        }
        Integer memberId = Integer.parseInt (mem);
        List<TMemberAddress> tMemberAddresses = tMemberService.listAddredd (memberId);
        ArrayList<UserAddressVo> userAddressVos = new ArrayList<> ();

        for (TMemberAddress tMemberAddress : tMemberAddresses) {
            UserAddressVo userAddressVo = new UserAddressVo();
            userAddressVo.setId (tMemberAddress.getId());
            userAddressVo.setAddress (tMemberAddress.getAddress());
            userAddressVos.add (userAddressVo);
        }
        return   AppResponse.ok(userAddressVos);
    }
}
